/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.company.App;

import com.company.Logic.Converter;
import com.company.Logic.MeasureMapper;
import com.company.builders.BuilderCurve;
import com.company.graphics.builders.JFreeChartBuilder;
import com.company.primitivies.Circle;
import com.company.primitivies.Curve;
import com.company.primitivies.Ellipse;
import com.company.primitivies.Point2d;
import java.awt.BorderLayout;
import java.awt.Container;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.xy.XYSeries;
import org.jzy3d.analysis.AbstractAnalysis;
import org.jzy3d.chart.factories.AWTChartComponentFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Builder;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;

/**
 *
 * @author admin
 */
public class App extends AbstractAnalysis {

    public static void main(String[] args) throws Exception {
        // AnalysisLauncher.open(new App());
        double a = 384.748;
        double e = 0.0549006;
        double b = a * Math.sqrt(1 - e * e);
        // double h = 0.00025;
        double h = 0.001;
        Ellipse ell = new Ellipse(a, b);

        List<Point2d> listPoint = new ArrayList<>();
        List<Point2d> points = ell.generateListPoint(h);
        int i = 0;
        while (i < points.size()) {
            listPoint.add(points.get(i));
            i += 1000;
        }

        Circle circle = new Circle(6.371, ell.getC(), 0);

        List<XYSeries> list = new ArrayList<>();
        for (Point2d var : listPoint) {
            Curve curve = new Curve(ell, var);
            BuilderCurve builderCurve = new BuilderCurve(curve);
            list.add(Converter.convertToXYSeries(builderCurve.fullCase(h), var.toString()));
        }
        list.add(Converter.convertToXYSeries(ell.generateListPoint(h), "ellipse"));

        list.add(Converter.convertToXYSeries(circle.generateListPoint(h), "circle"));

        JFreeChartBuilder builder = new JFreeChartBuilder(list, a);
        JFreeChart chart = builder.buildGraphics();
        JFrame frame
                = new JFrame("MinimalStaticChart");

        frame.getContentPane()
                .add(new ChartPanel(chart));
        frame.setSize(800, 800);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    @Override
    public void init() throws Exception {
        double a = 10;
        double b = 9;
        double h = 0.00025;
        Mapper mapper = new MeasureMapper(a, b, h);
        Ellipse ell = new Ellipse(a, b);
        double x = ell.genX(0);
        double x1 = ell.genX(1.9 * Math.PI);
        double y = ell.genY(0);
        double y1 = ell.genY(1.9 * Math.PI);

        Range xRange = new Range(x, x1);
        Range yRange = new Range(y, y1);
        int steps = 130;
        final Shape surface = Builder.buildOrthonormal(new OrthonormalGrid(xRange, steps, yRange, steps), mapper);
        surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
        surface.setFaceDisplayed(true);
        surface.setWireframeDisplayed(false);

        chart = AWTChartComponentFactory.chart(Quality.Advanced, getCanvasType());
        chart.getScene().getGraph().add(surface);
    }
}
